package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CourSeorder;
import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.qo.CourSeorderQuery;
import cn.wolfcode.crm.service.ICourSeorderService;
import cn.wolfcode.crm.service.ICustomerService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/courSeorder")
public class CourSeorderController {

    @Autowired
    private ICourSeorderService courSeorderService;
    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;
    @Autowired
    private ICustomerService customerService;

    @RequestMapping("/list")
    @RequiresPermissions(value = {"courSeorder:list","班级页面"},logical = Logical.OR)
    public String list(Model model, @ModelAttribute("qo")CourSeorderQuery qo){
        //课程订单数据
        PageInfo pageInfo = courSeorderService.query(qo);
        model.addAttribute("result",pageInfo);
        //销售课程
        List<SystemDictionaryItem> sys=systemDictionaryItemService.selectBySn("subject");
        model.addAttribute("sys",sys);

        //选择客户数据
        List<Customer> empsAll = customerService.selectByStatusId(0,1);
        model.addAttribute("empsAll",empsAll);
        return "/courseorder/list";
    }

    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value = {"courSeorder:saveOrUpdate","班级新增/编辑"},logical = Logical.OR)
    public JsonResult saveOrUpdate(CourSeorder courSeorder){
        if (courSeorder.getId() == null) {
            courSeorderService.save(courSeorder);
        }else{
            courSeorderService.updateByPrimaryKey(courSeorder);
        }
        return new JsonResult();
    }

    @RequestMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = {"courSeorder:delete","班级删除"},logical = Logical.OR)
    public JsonResult delete(Long id){
        courSeorderService.deleteByPrimaryKey(id);
        return new JsonResult();
    }
}
